var t, e = getApp(), a = e.globalData.url, n = require("../../../utils/util.js");

Page({
    data: {
        cardList: [],
        hidden: !0,
        domain: a,
        ishidden: !1
    },
    onLoad: function(e) {
        (t = this).getPhoneRegister(), t.getImage(), wx.getStorageSync("UserPhone") ? t.getCardInfo() : t.setData({
            hidden: !1
        });
    },
    onShow: function() {},
    getCardInfo: function() {
        var t = this, a = e.globalData.token;
        n.request(e, "wx/cust/getWxCustCardByPhone", "GET", {
            token: a
        }, function(e) {
            var a = e.data;
            a.forEach(function(t) {
                t.remainNum = n.convertMath(t.remainNum);
            }), t.setData({
                cardList: a
            });
        }, function(t) {});
    },
    confirm: function(t) {
        var e = this;
        wx.getStorageSync("UserPhone") ? (e.setData({
            hidden: !0
        }), e.getCardInfo()) : wx.showToast({
            title: "请先绑定手机",
            icon: "none"
        });
    },
    cancelPhone: function() {
        this.setData({
            hidden: !0
        }), wx.navigateBack({});
    },
    getPhoneNumber: function(t) {
        var a = this;
        wx.setStorageSync("ivPhone", t.detail.iv), wx.setStorageSync("encryptedDataPhone", t.detail.encryptedData), 
        n.registerPhone(t.detail.encryptedData, t.detail.iv, e), a.setData({
            hidden: !0
        });
    },
    getPhoneRegister: function() {
        var t = this, a = e.globalData.token;
        n.request(e, "wx/cust/hasPhone", "POST", {
            token: a
        }, function(e) {
            e.state && (null != e.data && null != e.data.phone && "" != e.data.phone ? (t.setData({
                hidden: !0
            }), wx.setStorageSync("UserPhone", !0)) : (t.setData({
                hidden: !1
            }), wx.setStorageSync("UserPhone", !1)));
        });
    },
    getImage: function() {
        var t = this, a = e.globalData.token;
        n.request(e, "wx/sys/getCardsUrl", "GET", {
            token: a
        }, function(e) {
            e.state && t.setData({
                img1: e.data[0].url,
                img2: e.data[1].url
            });
        }, function(t) {});
    },
    cancelModal: function() {
        t.setData({
            ishidden: !0
        });
    },
    history: function() {
        wx.navigateTo({
            url: "../acountInfo/index"
        });
    }
});